package com.admin.interfaces.web;

import com.admin.application.OrderService;
import com.admin.interfaces.facade.dto.OrderQueryDTO;
import com.admin.utils.OrderStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 订单管理
 *
 * @author LeeJun
 * @time 2017-4-24 21:14
 */
@Controller
@RequestMapping("/order")
public class OrderController {

    @Autowired
    protected OrderService orderService;


    @RequestMapping(method = RequestMethod.GET)
    public String list(Model model, OrderQueryDTO queryDTO) {
        model.addAttribute("query", queryDTO);
        model.addAttribute("list", orderService.list(queryDTO));
        return "order/list";
    }

    @RequestMapping(value = "detail", method = RequestMethod.GET)
    public String detail(Model model, String id) {
        model.addAttribute("detail", orderService.detail(id));
        return "order/detail";
    }

    @RequestMapping(value = "remark", method = RequestMethod.POST)
    public String remark(Model model, String id, String remark) {
        orderService.updateRemark(id, remark);
        model.addAttribute("detail", orderService.detail(id));
        return "redirect:/order/detail?id=" + id;
    }

    /**
     * 根据营业员id查询订单
     * @param model
     * @param id
     * @return
     */
    @RequestMapping(value = "findOrderByUserId/{id}", method = RequestMethod.GET)
    public String findOrderByUserId(Model model, @PathVariable("id") String id) {
        model.addAttribute("list", orderService.listByStatusAndUserId( OrderStatus.VERIFIED.name(),id));
        return "order/userOrder";
    }

}
